home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoChangeSlotByteCounts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.1 KB  |  261 lines

  1. /*
  2.  *   $RCSfile: undoChangeSlotByteCounts.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:04 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38.  
  39. #include "sysdefs.h"
  40. #include "ess.h"
  41. #include "checking.h"
  42. #include "trace.h"
  43. #include "error.h"
  44. #include "list.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "pool.h"
  57. #include "log.h"
  58. #include "volume.h"
  59. #include "trans.h"
  60. #include "logrecs.h"
  61. #include "logaction.h"
  62. #include "openlog.h"
  63. #include "undo.h"
  64. #include "undo_extfuncs.h"
  65. #include "bf_extfuncs.h"
  66. #include "log_extfuncs.h"
  67. #include "log_intfuncs.h"
  68. #include "util_funcs.h"
  69. #include "thread_globals.h"
  70. #include "bf_globals.h"
  71. #include "trans_globals.h"
  72. #include "sm_macro.h"
  73. #ifdef INIT_LRC_IS_LSN
  74. #    include "log_globals.h"
  75. #endif
  76.  
  77.  void
  78. undoChangeSlotByteCounts(
  79.  
  80.     LOGRECORDHDR        *recordHeader 
  81. )
  82. {
  83.  
  84.     GROUPLINK            *groupLink;
  85.     LGNODE                *lgNode;
  86.     SLOTTEDPAGE         *slottedPage;
  87.     PAGETYPE            pageType;
  88.     PAGE2SIZE           page2size;
  89.     PAGESLOT            *slotPtr;
  90.     SMALLOBJ            *objPtr;
  91.     LRC                 *pageLRC;
  92.     PID                    *pid;
  93.     LGSLOTUPDATEINFO         *slotUpdateInfo;
  94.     LOGRECORDINFO       recordInfo;
  95. #ifdef INIT_LRC_IS_LSN
  96.     LRC                 tempLRC;
  97.     LRC                 *lrc = &tempLRC;
  98. #else
  99.     LRC                 *lrc;
  100. #endif /* INIT_LRC_IS_LSN; */
  101.     LSN                    lsn;
  102.     FORCEMARK            forceMark;
  103.     BOOL                actionDone;    /* Indicates whether the action
  104.                                        was ever performed on the page */
  105.     int                    i;
  106.     INIT_MISSING_UPDATE_INFO( Active->transRec );
  107.  
  108.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN));
  109.  
  110.     /*
  111.      *    get a pointer to the page for the record
  112.      */
  113.     pid = &(recordHeader->actionPid);
  114.     TRPRINT(TR_IO|TR_LOG, TR_LEVEL_2, ("pid:%d", pid->page));
  115.  
  116.     /*
  117.      *    get pointer to oid, header info
  118.      */
  119.     slotUpdateInfo = (LGSLOTUPDATEINFO*) GET_LOG_IMAGE(recordHeader, 0);
  120.  
  121.     /*
  122.      *    read in the page
  123.      */
  124.    if (slotUpdateInfo->rootSlot != NIL) {
  125.         pageType = PAGE_SLOTTED;
  126.         page2size = SLOTTED_PAGE2SIZE;
  127.     } else {
  128.         pageType = PAGE_LARGENODE;
  129.         page2size = LG_PAGE2SIZE;
  130.     }
  131.     if ((groupLink = bf_ReadPage(UserBufGroup, pid, page2size, BF_SEM)) == NULL) {
  132.  
  133.         SM_ERROR(TYPE_FATAL, Active->errno);
  134.     }
  135.     groupLink->pageHash->pageType = pageType;
  136.  
  137.     /*
  138.      *    get a pointer to the large node page
  139.      */
  140.     if (slotUpdateInfo->rootSlot == NIL) {
  141.         lgNode = (LGNODE *) groupLink->bufFrame;
  142.         pageLRC = &(lgNode->header.lrc);
  143.         CHECK_LARGENODE_MAGIC(lgNode);
  144.     } else {
  145.         /*
  146.          *  Root node on slotted page
  147.          */
  148.         slottedPage = (SLOTTEDPAGE *) groupLink->bufFrame;
  149.         pageLRC = &(slottedPage->header.lrc);
  150.         SM_ASSERT(LEVEL_3, !CHECK_SLOTTED_MAGIC(slottedPage));
  151.     }
  152.  
  153.     /*
  154.      *    See if the action was actually done
  155.      */ 
  156.     actionDone = compareLRC(&(recordHeader->actionLRC), pageLRC ) <= 0;
  157.     
  158.     /*
  159.      *    it is possible that the action 
  160.      *    never made it to the page on the server, so missing update
  161.      *    information may need to be recorded
  162.      *
  163.      *    Process any missing updates, and return a pointer to
  164.      *    the lrc to increment.  This will either be the lrc on the
  165.      *    slotted page, or the lrc in the missingUpdatePageTable
  166.      */
  167.     RECORD_MISSING_UPDATE(actionDone, &lrc, missingUpdateInfo, pid, 
  168.              pageLRC, groupLink->pageHash, recordHeader, PAGE_LARGENODE);
  169.  
  170.     /*
  171.      *    increment the lrc on the page
  172.      */
  173.     GENERATE_LRC(lrc);
  174.  
  175.     /*
  176.      *    Log the undo write
  177.      */
  178.     if (recordHeader->action == LOG_ACTION_INCREMENT_SLOT_BYTECOUNTS) {
  179.         recordInfo.action       = LOG_ACTION_DECREMENT_SLOT_BYTECOUNTS;
  180.     } else {
  181.         recordInfo.action       = LOG_ACTION_INCREMENT_SLOT_BYTECOUNTS;
  182.     }
  183.     recordInfo.type         = LOG_REC_TYPE_COMPENSATION;
  184.     recordInfo.imageCount   = 1;
  185.     recordInfo.actionPid    = pid;
  186.     recordInfo.actionLRC    = lrc;
  187.     recordInfo.imageSize[0] = sizeof(LGSLOTUPDATEINFO);
  188.     recordInfo.imageData[0] = (VOID *) slotUpdateInfo;
  189.     recordInfo.nextUndoLSN  = recordHeader->previousLSN;
  190.     recordInfo.flags        = NOFLAGS;
  191.  
  192.     /*
  193.      *    write the record to the log
  194.      */
  195.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  196.                               &lsn, NOFLAGS)) < 0)  {
  197.         SM_ERROR(TYPE_FATAL, Active->errno);
  198.     }
  199.  
  200.     /*
  201.      *    mark the page dependency
  202.      */
  203. #ifndef INIT_LRC_IS_LSN
  204.     DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  205. #endif
  206.  
  207.     /*
  208.      *    perform the undo, if the action was performed
  209.      */
  210.     if (actionDone) {
  211.  
  212. #ifdef INIT_LRC_IS_LSN
  213.         DEPEND_LOG(groupLink->pageHash, forceMark, &lsn, lrc);
  214. #endif
  215.  
  216.         /*
  217.          *    get a pointer to the large node page
  218.          */
  219.         if (slotUpdateInfo->rootSlot != NIL) {
  220.             /*
  221.              *  Root node on slotted page
  222.              */
  223.             SM_ASSERT(LEVEL_3, slotUpdateInfo->rootSlot < slottedPage->header.slotCount);
  224.             slotPtr = GETSLOTPTR(slottedPage, slotUpdateInfo->rootSlot);
  225.             objPtr = GETOBJECTPTR(slottedPage, slotPtr);
  226.             lgNode = (LGNODE*) objPtr->data;
  227.             CHECK_SLOTROOT_MAGIC(lgNode);
  228.         }
  229.  
  230.         /*
  231.          *  Perform the undo by incrementing/decrementing all the
  232.          *  required slot counts.  Two loops are required since the
  233.          *  size to increment/dec by may not fit in a signed field.
  234.          */
  235.         if (recordHeader->action == LOG_ACTION_INCREMENT_SLOT_BYTECOUNTS) {
  236.  
  237.             for(i = slotUpdateInfo->start; i < lgNode->header.numSlots; i++) {
  238.                 lgNode->slot[i].count -= slotUpdateInfo->size;
  239.             }
  240.         } else {
  241.             SM_ASSERT(LEVEL_3, recordHeader->action == LOG_ACTION_DECREMENT_SLOT_BYTECOUNTS);
  242.             for(i = slotUpdateInfo->start; i < lgNode->header.numSlots; i++) {
  243.                 lgNode->slot[i].count += slotUpdateInfo->size;
  244.             }
  245.         }
  246.  
  247.     }
  248.  
  249.     /*
  250.      *    signal the semaphore and unfix the page, dirty the page if
  251.      *    the action was done
  252.      */
  253.     signalSemaphore( &(groupLink->pageHash->semaphore) );
  254.     bf_UnfixPage(groupLink, BF_DEFAULT, actionDone);
  255.  
  256.     /*
  257.      *    return success
  258.      */
  259.     return;
  260. }
  261.